   $(function() {
	   var  table = $('#table_role');
		 var form = $('#modal_new_role').serializeObject();
		table.dataTable({
					"processing" : true,
					// 开启服务器模式
					serverSide : true,
					"ajax" : {
						url : "/a/wxconf/group/getspellgroupsOrder",
						data:{}// 列表查询
					},
					"autoWidth" : false,
					"columns" : [
						{
							"width" : "10%",
							"data" : "orderNO",
						},

						{
							"width" : "10%",
							 "render" : function(data, type, row, meta) {
							
									 if(row.orderProductDetail){
										 var productName=row.orderProductDetail.productName;
										 var productSpec=row.orderProductDetail.productSpec;
										 var productSpec1=row.orderProductDetail.productSpec1;
										 var productSpec2=row.orderProductDetail.productSpec2;
										 if(productSpec2){
											 return productName+" "+productSpec+productSpec1+productSpec2;
										 }else  if(productSpec1){
											 return productName+" "+productSpec+productSpec1;
										 }else if(productSpec){
											 return productName+" "+productSpec;
										 }else{
											 return productName;
										 }
									 }else{
										 return "--";
									 }
								
							
						} 
						},
						
					
							{ 
								     "width" : "10%", //数量 orderProductDetail
									 "render" : function(data, type, row, meta) {
										 if(row.orderProductDetail){
											 return row.orderProductDetail.count;
										 }else{
											 return "--";
										 }
									} 
							},
							{
								"width" : "10%",
								 "render" : function(data, type, row, meta) {
								 if(row.spellGroups){
									 if(row.orderProductDetail.price){
										 return row.orderProductDetail.price/100;

									 }else{
										 return "--";
									 }
								 }else{
									 return "--";
								 }
							} 
							},
							{
								"width" : "10%",
								 "render" : function(data, type, row, meta) {
									 if(row.total){
										 return row.total/100;
									 }else{
									 return "--";
								 }
							} 
							},
						
						
							{
								"width" : "10%",
								"data":"user.mobile"
							},
							{
								"width" : "10%",
								 "render" : function(data, type, row, meta) {
								 if(row.creatDate){
									 return moment(row.creatDate).format('YYYY-MM-DD HH:mm');
								 }else{
									 return "--";
								 }
							} 
							},
							{
								"width" : "10%",
								//订单状态 1=代付款， 2=待发货，3=待收货，4=已完成，5=已失效，6=售后，7=已消费，8=未消费，9=拼团中
								 "render" : function(data, type, row, meta) {
								 if(row.status=="1"){
									 return "待付款";
								     }else if(row.status=="2"){
										 return "待发货";
									 }else if(row.status=="3"){
										 return "待收货";
									 }else if(row.status=="4"){
										 return "已完成";
									 }else if(row.status=="5"){
										 return "已失效";
									 }else if(row.status=="6"){
										 return "售后";
									 }else if(row.status=="7"){
										 return "已消费";
									 }else if(row.status=="8"){
										 return "未消费";
									 }else if(row.status=="9"){
										 return "拼团中";
									 }else{
										 return "";
									 }
								 }
							},
							{
								"width" : "10%",
								"data": "status",
								 "render" : function(data, type, row, meta) {
									// 到店和不到店
										var val="--";
												switch (data) {
												case 2:
													val="<button type=\"button\"  class=\"btn  blue shipments\">发货</button>";
													break;
												case 7:
													val="<button type=\"button\" class=\"btn  green btn_see_order1\">详情</button>";
													break;
												case 8:
													val="<button type=\"button\" class=\"btn  green btn_see_order1\">详情</button>";
													break;
												default:
													val="<button type=\"button\" class=\"btn  green btn_see_order\">详情</button>";
												break;
												}
									 return val;
									}        
							} ],
					"language" : {
						"lengthMenu" : "每页显示 _MENU_ 条记录",
						"emptyTable" : "暂无数据记录",
						"info" : "显示 _START_ 至 _END_ 条数据，共 _TOTAL_ 条记录！",
						"zeroRecords" : "没有搜索到匹配记录",
						"infoEmpty" : "",
						"infoFiltered" : "",
						"processing" : ""
					},
					"destroy" : true,
					"ordering": false, 
					"pageLength" : 5,
					"order" : [ [ 0, "desc" ] ],
					"columnDefs" : [ {
						"orderable" : false,
						"targets" : [ 0,1,2,3,4,5,6,7]
					} ],
					"dom" : "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>"
							+ "<t>" + "<'row'<'col-md-5'i><'col-md-7'>p>",
					"fnInitComplete" : function() {
					}
				});
		
		$('#doQuery').click(function(event){
			 var form = $('#searchForm').serializeObject();
			/*   if(form.creatDateStr1=="" ){
				   alert("请选择下单开始时间");
				   return;
			   }
			   if( form.creatDateStr2==""){
				   alert("请选择下单结束时间");
				   return;
			   }*/
			   var con1;
			   var con2;
			   $("#tabs1 li").each(function(){
				   if($(this).hasClass("active")){
						con1 =	$(this).val();
					}
			   })
			   
			   if( $(".ul1").css("display")=="block"){
				   $(".ul1 li").each(function(){
					   if($(this).hasClass("active")){
							con2 =	$(this).val();
						}
				   })
			   }else{
				   $(".ul2 li").each(function(){
					   if($(this).hasClass("active")){
							con2 =	$(this).val();
						}
				   })
			   }
			  // alert("con1:"+con1+"con2:"+con2);
				 var param =  {
						"status" : con2,
						"type":con1,
						"creatDateStr1":form.creatDateStr1,
						"creatDateStr2":form.creatDateStr2,
						"params":form.params
					}
				 $('#table_role').DataTable().search(JSON.stringify(param)).draw();
		})
		
		// 查看订单详情
		table.on('click', '.btn_see_order', function(event) {
			var oData_arr = table.DataTable().rows($(this).parents("tr"))
			.data(); // 操作行对象
			var _id = oData_arr[0].id;
			window.location.href="/p/user/order/view?id="+ encodeURIComponent(_id);
		});
		// 查看到店订单详情
		table.on('click', '.btn_see_order1', function(event) {
			var oData_arr = table.DataTable().rows($(this).parents("tr"))
			.data(); // 操作行对象
			var _id = oData_arr[0].id;
			window.location.href="/p/user/storeOrder/view1?id="+ encodeURIComponent(_id);
		});
		table.on('click', '.shipments', function(event) {
			var oData_arr = table.DataTable().rows($(this).parents("tr"))
			.data(); // 操作行对象
			var _id = oData_arr[0].id;
			//window.location.href="/p/user/storeOrder/view1?id="+ encodeURIComponent(_id);
		   	window.location.href="/p/user/order/shipments?id="+ encodeURIComponent(_id);

		});
		
   })
   
   function dochang(num){
	   var con1;
	   var con2;
	   if(num=="0"){
		   $(".ul1").css("display","block");
		   $(".ul2").css("display","none");
		   con1 = num;
		   $(".ul1 li").each(function(){
			   if($(this).hasClass("active")){
					con2 =	$(this).val();
				}
		   })
	   }else if(num=="1"){
		   con1 = num;
		   $(".ul2").css("display","block");
		   $(".ul1").css("display","none");
		   $(".ul2 li").each(function(){
			   if($(this).hasClass("active")){
					con2 =	$(this).val();
				}
		   })
	   }else{
		   con2 = num;
		   $("#tabs1 li").each(function(){
				   if($(this).hasClass("active")){
						con1 =	$(this).val();
					}
			   })
		   }
	   var form = $('#form1').serializeObject();
		 var form1 = $('#searchForm').serializeObject();
		 var param =  {
				"status" : con2,
				"type":con1,
				"creatDateStr1":form1.creatDateStr1,
				"creatDateStr2":form1.creatDateStr2,
				"params":form1.params
			}
		 $('#table_role').DataTable().search(JSON.stringify(param)).draw();
   }
   
/*// 发货
   function shipments(dom){
   //	var oData_arr = $('#table_role').DataTable().rows(dom.parents("tr")).data(); // 操作行对象
   	var oData_arr = $('#table_role').DataTable().rows($(this).parents("tr"))
	.data(); // 操作行对象
   	var _id = oData_arr[0].id;
   	window.location.href="/p/user/order/shipments?id="+ encodeURIComponent(_id);
   };*/
   
// 发货
   function shipments(dom){
   	var oData_arr = $('#table_order').DataTable().rows(dom.parents("tr")).data(); // 操作行对象
   	var _id = oData_arr[0].id;
   	window.location.href="/p/user/order/shipments?id="+ encodeURIComponent(_id);
   };
   
